import axios from "axios";
import service from "@/config/index";

const rmsAxios = axios.create();

function addAuthorizationSearch (config) {
  let headers = config.headers;
  let token = sessionStorage.getItem("token");
  if (token) {
    headers["Authorization"] = "Bearer " + token;
  } else {
    config.data = config.data
  }
}

// axios默认配置
rmsAxios.defaults.timeout = 60000; // 超时时间
rmsAxios.defaults.baseURL = process.env.VUE_APP_URL;

// http request 拦截器
rmsAxios.interceptors.request.use(
  (config) => {
    config.headers["Content-Type"] = "application/json;charset=UTF-8";
    config.headers["Access-Control-Allow-Origin"] = "*";
    config.headers["Access-Control-Allow-Header"] = "Content-Type,*";
    addAuthorizationSearch(config);
    return config;
  },
  (error) => {
    return Promise.reject(error.response);
  }
);

const SCHEMAS = {
  Turnover: `${service.serviceReport}/customer/customerTurnoverDetails`,
  Costs: `${service.serviceReport}/carrier/carrierCostsDetails`,
  MethodCost: `${service.serviceReport}/carrier/carrierShippingMethodCostDetails`,
  ModeCost: `${service.serviceReport}/carrier/carrierShippingModeCostDetails`,
  Profit: `${service.serviceReport}/profits/shipperProfitDetails`,
  Goods: `${service.serviceReport}/carrier/signExceptionList`,
  ConsignerGoods: `${service.serviceReport}/customer/signExceptionList`,
  //综合考核 明细
  CustomerPickTime: `${service.serviceReport}/customer/customerDeliveryTimeoutDetails`,
  CarrierPickTime: `${service.serviceReport}/carrier/carrierDeliveryTimeoutDetails`,
  CustomerDeliverTime: `${service.serviceReport}/customer/customerDeliverTimeOutDetails`,
  CarrierDeliverTime: `${service.serviceReport}/carrier/carrierDeliverTimeOutDetails`,
  CustomerSignTime: `${service.serviceReport}/customer/customerSignTimeoutDetails`,
  CarrierSignTime: `${service.serviceReport}/carrier/carrierSignTimeoutDetails`,
  CustomerGoodException: `${service.serviceReport}/customer/customerGoodExceptionDetails`,
  CarrierGoodException: `${service.serviceReport}/carrier/carrierGoodExceptionDetails`,
  CustomerReceiptTime: `${service.serviceReport}/customer/customerReceiptTimeOutDetails`,
  CarrierReceiptTime: `${service.serviceReport}/carrier/carrierReceiptTimeOutDetails`,
};
export default {
   // 营业额明细
   search (params, menuId) {
    let url
    switch (menuId) {
      case 311:
        url = 'Turnover'
        break
      case 321:
      case 322:
        url = 'Costs'
        break
      case 323:
        url = 'MethodCost'
        break
      case 324:
        url = 'ModeCost'
        break
      case 335:
        url = 'Profit'
			  break
      case 367:
        url = 'Goods'
        break
      case 368:
        url = 'ConsignerGoods'
        break
      case 3181:
          url = 'CustomerPickTime'
          break
      case 3182:
        url = 'CustomerDeliverTime'
        break
      case 3183:
        url = 'CustomerSignTime'
        break
      case 3184:
        url = 'CustomerGoodException'
        break
      case 3185:
        url = 'CustomerReceiptTime'
        break
      case 3321:
        url = 'CarrierPickTime'
        break
      case 3322:
        url = 'CarrierDeliverTime'
        break
      case 3323:
        url = 'CarrierSignTime'
        break
      case 3324:
        url = 'CarrierGoodException'
        break
      case 3325:
        url = 'CarrierReceiptTime'
        break
    }
    return rmsAxios.post(SCHEMAS[url], params);
  }
};